/****************************************************************************
*                                                                           *
* dxCamera.h -- Camera Settings                                             *
*                                                                           *
* Copyright (c) Ionescu Marius. All rights reserved(2009).                  *
*                                                                           *
****************************************************************************/

#pragma once
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9tex.h>

class dxCamera
{
	public:
		dxCamera(void);
		dxCamera(D3DXVECTOR3 startPos);
		~dxCamera(void);

		bool createCamera(LPDIRECT3DDEVICE9 device, float nearView, float farView);
		void setLookAt(D3DXVECTOR3 newTarget);
		void setPosition(D3DXVECTOR3 newPosition);
		void resetView();
		
		void CalculateViewMatrix(D3DXMATRIX *viewMatrix);
		void SetPosition(const D3DXVECTOR3 &pos) {m_position=pos;}
		void SetYawPitchRoll(float yaw,float pitch, float roll);	

		//GETS
		float GetYaw() const {return m_yaw;}
		float GetPitch() const {return m_pitch;}
		float GetRoll() const {return m_roll;}
		D3DXVECTOR3 GetPosition() const {return m_position;}	

		// Move operations
		void MoveForward(float amount) {m_position+=m_look*amount;}
		void MoveRight(float amount) {m_position+=m_right*amount;}
		void MoveUp(float amount) {m_position+=m_up*amount;}

		// Rotations
		void Yaw(float amount); // rotate around y axis
		void Pitch(float amount); // rotate around x axis
		void Roll(float amount); // rotate around z axis

	private:

		D3DXMATRIX viewMatrix; //the view matrix
		D3DXMATRIX projectionMatrix; // the projection matrix
		D3DXVECTOR3 target;		// Camera Target
		D3DXVECTOR3 position;		// Position of camera
		float nearClip;
		float farClip;
		LPDIRECT3DDEVICE9 d3dDevice;
		
		D3DXVECTOR3 m_position; // camera position
		float m_yaw;	// rotation around the y axis
		float m_pitch;	// rotation around the x axis
		float m_roll;	// rotation around the z axis
		D3DXVECTOR3 m_up,m_look,m_right; // camera axis
		float RestrictAngleTo360Range(float angle) const;
};
